package com.ncu.sports.service.Impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ncu.sports.mapper.UserMapper;
import com.ncu.sports.pojo.User;
import com.ncu.sports.service.UserService;
import com.sun.javaws.IconUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public int getUserByUsernameAndPassword(User user) {
        int count = userMapper.getUserByUsernameAndPassword(user.getUsername(),user.getPassword());
        return count;
    }

    @Override
    public PageInfo<User> getUserByUsername(String name,int currentPage,int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> list = userMapper.getUserByUsername(name);
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int updateStateById(User user) {
        int count = userMapper.updateStateById(user);
        return count;
    }

    @Override
    public int insertUser(User user) {
        int count = userMapper.insertUser(user);
        return count;
    }

    @Override
    public int deleteUser(int id) {
        int count = userMapper.deleteUser(id);
        return count;
    }

    @Override
    public User getUpdateUser(int id) {

        User user = userMapper.getUpdateUser(id);
        return user;
    }

    @Override
    public int updateUser(User user) {
        int count = userMapper.updateUser(user);
        return count;
    }

    @Override
    public User getUpdateRole(int id) {
        User role = userMapper.getUpdateRole(id);
        return role;
    }

    @Override
    public int updateRole(User user) {
        int count = userMapper.updateRole(user);
        return count;
    }

/*    @Override
    public PageInfo<User> getUser(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> list = userMapper.getUser();
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }*/
}
